﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WpfStarterKit.Framework.Util;

namespace WpfStarterKit.Framework.Navigation
{
    /// <summary>
    /// The ApplicationManager is a singleton class that holds references to the NavigationManager and ExceptionHandler
    /// </summary>
    public class ApplicationManager
    {
        private static readonly object SyncRoot = new Object();

        private ApplicationManager()
        {
        }

        private static volatile ApplicationManager _instance;
        /// <summary>
        /// Get the single instance of ApplicationManager
        /// </summary>
        public static ApplicationManager Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (SyncRoot)
                    {
                        if (_instance == null)
                        {
                            _instance = new ApplicationManager();
                        }
                    }
                }

                return _instance;
            }
        }

        private ExceptionHandler _exceptionHandler;
        /// <summary>
        /// An instance of the application's exception handler
        /// </summary>
        public ExceptionHandler ExceptionHandler 
        { 
            get
            {
                if(_exceptionHandler == null)
                {
                    _exceptionHandler = new ExceptionHandler();
                }

                return _exceptionHandler;
            }
            set
            {
                _exceptionHandler = value;
            }
        }

        /// <summary>
        /// An instance of the application's navigation manager
        /// </summary>
        public NavigationManager Navigation { get; set; }

        private LongRunningOperationManager _longRunningOperations;
        /// <summary>
        /// Determines what happens when a long running operation begins or ends. Override this class to add
        /// application-specific behaviour
        /// </summary>
        public LongRunningOperationManager LongRunningOperations
        {
            get
            {
                if(_longRunningOperations == null)
                {
                    _longRunningOperations = new LongRunningOperationManager();
                }

                return _longRunningOperations;
            }
            set
            {
                _longRunningOperations = value;
            }
        }
    }
}
